package com.wsd.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wsd.bean.Admin;
import com.wsd.dao.AdminDaoInterface;

/**
 * A data access object (DAO) providing persistence and search support for Admin
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see com.wsd.bean.Admin
 * @author MyEclipse Persistence Tools
 */

public class AdminDAO extends HibernateDaoSupport implements AdminDaoInterface {
	private static final Log log = LogFactory.getLog(AdminDAO.class);

	protected void initDao() {
		// do nothing
	}

	public void save(Admin transientInstance) {
		log.debug("saving Admin instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Admin persistentInstance) {
		log.debug("deleting Admin instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Admin findById(java.lang.Integer id) {
		log.debug("getting Admin instance with id: " + id);
		try {
			Admin instance = (Admin) getHibernateTemplate().get(
					"com.wsd.bean.Admin", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findByExample(Object exampleEntity) {
		log.debug("finding by Products instances");
		try {
			return getHibernateTemplate().findByExample(exampleEntity);
		} catch (RuntimeException re) {
			log.error("find example failed", re);
			throw re;
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<Admin> findAll() {
		log.debug("finding all Admin instances");
		try {
			String queryString = "from Admin";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.AdminDaoInterface#update(com.wsd.bean.Admin)
	 */
	public void update(Admin admin) {
		getHibernateTemplate().update(admin);
	}
}